// packagePay/pages/insurance-apply-time/insurance-apply-time.js
import { addWesureTime } from '../../api/insurance'
import {toast,dateFormat } from '../../../utils/util'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        id:'',
        increaseTime:'',
        reason:'',
        companyName:''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options){
        console.log('options',options)
        this.setData({
            id:options.id,
            companyName:options.companyname
        })
    },
    dayBindTimeChange(event){
        const date = dateFormat('YY-mm-dd',new Date()) + ' ' + event.detail.value + ':00'
        const time =  Date.create(date).getTime() + 1000*60*30
        const delayTime = dateFormat('HH:MM',new Date(time))
        this.setData({
            increaseTime:event.detail.value + '-' + delayTime
        })
    },
    onSteReason(event){
        this.setData({
            reason:event.detail.value
        })
    },
    onSubmit(){
        if(!this.data.increaseTime){
            toast('请选择时间')
            return
        }
        if(!this.data.reason){
            toast('申请理由为空')
            return
        }
        addWesureTime({
            serveCompanyId:this.data.id,
            remark:this.data.reason,
            wesureTimeAddAudit:this.data.increaseTime
        }).then(res=>{
            toast('申请成功')
            wx.navigateTo({
                url: '/packageInsurance/pages/insurance-apply-time-success/insurance-apply-time-success?increaseTime=' + this.data.increaseTime + '&remark=' + this.data.reason,
            })
        })
    }
})